package com.xh.jf_blog.controller.front;

import com.xh.jf_blog.bean.ArticleLike;
import com.xh.jf_blog.common.util.R;
import com.xh.jf_blog.common.util.SessionInfo;
import com.xh.jf_blog.service.ArticleLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Author PangJunjie
 * @Date 2024/2/22/022
 */
@RestController
public class LikeController extends SessionInfo {
    @Autowired
    private ArticleLikeService articleLikeService;

    @GetMapping("/follow/{authorId}")
    public R saveFollow(@PathVariable int authorId) {
        ArticleLike articleLike = new ArticleLike();
        articleLike.setType(3);
        articleLike.setOptId(getVipId());
        articleLike.setInfoId(authorId);
        articleLike.setOptTime(new Date());
        articleLikeService.save(articleLike);
        return R.ok();
    }

    @GetMapping("/collection/{articleId}")
    public R saveCollection(@PathVariable int articleId) {
        ArticleLike articleLike = new ArticleLike();
        articleLike.setType(2);
        articleLike.setOptId(getVipId());
        articleLike.setInfoId(articleId);
        articleLike.setOptTime(new Date());
        articleLikeService.save(articleLike);
        return R.ok();
    }

    @GetMapping("/like/{articleId}")
    public R saveLike(@PathVariable int articleId) {
        ArticleLike articleLike = new ArticleLike();
        articleLike.setType(1);
        articleLike.setOptId(getVipId());
        articleLike.setInfoId(articleId);
        articleLike.setOptTime(new Date());
        articleLikeService.save(articleLike);
        return R.ok();
    }

    @GetMapping("/article/{articleId}/like")
    public R likeListByArticleId(@PathVariable int articleId, int page, int limit) {
        return articleLikeService.getLikeListByArticleId(page, limit, articleId);
    }

    @GetMapping("/article/{articleId}/collection")
    public R collectionListByArticleId(@PathVariable int articleId, int page, int limit) {
        return articleLikeService.getCollectionListByArticleId(page, limit, articleId);
    }

}
